<template>
	<view class="postContainer">
	<view>
<!-- 		<uni-search-bar @confirm="search" :focus="false" v-model="searchValue"
		@blur="blur" @focus="focus" @input="input" @cancel="cancel" @change="change" @clear="clear"></uni-search-bar> -->
	</view>
	    <navigator url="/pages/setPost/setPost">
		<button class="button" type="primary" @click="inputDialogToggle"><text class="button-text">发布帖子</text></button>
		</navigator>
		<view class="showPost">
			<uni-card @click="imgClick" v-for="(item,index) in post" :key="index">
			<navigator :url="'/pages/postInfo/postInfo?newID='+item.newID">
				<image :src="item.imagelink" style="width: 100%;border-radius: 3%;"></image></navigator>
				<!-- <image slot='cover' style="width: 100%;" :src="cover"></image> -->
				<text class="uni-body">{{item.title}}</text>
				<view slot="actions" class="card-actions">
				<view class="card-actions-item" >
	<!-- 				@click="actionsClick('点赞')" -->
					<uni-icons :type="item.isLike ? 'hand-up-filled' : 'hand-up'" size="22" color="pink" @click="handleLike(index)"></uni-icons>
					<text class="card-actions-item-text">{{ item.likeNum>0 ? item.likeNum : '点赞' }}</text>
				</view>
				<view class="card-actions-item">
					<uni-icons type="chatbubble" size="22" color="#999" @click="handleComment"></uni-icons>
					<text class="card-actions-item-text_comment">{{item.commentNum}}</text>
				</view>
				</view>
		</uni-card>
		</view>
		
	</view>
	<view class="test" v-for="(item,index) in newsContent" :key="index">
		{{item}}
	</view>
	<view>
	</view>
	
</template>

<script setup>
	import { onMounted, ref } from 'vue';
	import {onShow} from '@dcloudio/uni-app'
	const likesCount = ref(0);
	const liked = ref();
	const inputDialog = ref(null);
	const commentsCount = ref(0);
	const newComment = ref('');
	const newsContent = ref([]);
	const app = getApp();
	const post = ref([]);
	import {
			baseUrl
		} from '../../tool/tool';
	onShow(()=>{
		console.log(2525);
		uni.request({
			url: baseUrl + "/Post/getAllPost?account="+app.globalData.account,
			method: "POST",
			success(res) {
				post.value=res.data;
			}
		})
	})
	const handleLike = (index) =>{
		if(!post.value[index].isLike){
			post.value[index].likeNum++;
			post.value[index].isLike = true;
			console.log(post.value[index].likeNum)
		}else{
			post.value[index].likeNum--;
			post.value[index].isLike = false;
		}
		uni.request({
			url:baseUrl+"/Post/setlike?account="+app.globalData.account+"&postID="+post.value[index].newID+"&num="+post.value[index].likeNum,
			method:'GET',
			success:(res) => {
				console.log("like "+res.data)
			}
		})
	}
	// function handleLike(){
	// 	if(!item.liked.value){
	// 		likesCount.value++;
	// 		liked.value = true;
	// 	}else{
	// 		liked.value = false;
	// 		likesCount.value--;
	// 	}
	// }
	// function submitComment(){
	// 	      if (newComment.value.trim() !== '') {
	// 	        commentsCount.value++;
	// 	        // 可以将评论内容提交到服务器，或者在本地保存等操作
	// 			newsContent.value.push(newComment.value);
	// 	        newComment.value = '';
	// 	        // showCommentDialog.value = false;
	// 	      }
	// }
	const searchValue = ref();
	function input(){
		console.log(searchValue);
		searchValue.value = searchValue
	}
	
	function search(){
		
		console.log(1);
	}
	
	function handleComment(){
		uni.navigateTo({
			url:"/pages/postInfo/postInfo"
		})
	}
	
</script>

<style lang="scss" scoped>
.card-actions {
		
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		height: 45px;
		border-top: 1px #eee solid;
	}
	.card-actions-item {
		
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.card-actions-item-text {
		font-size: 12px;
		color: pink;
		margin-left: 5px;
	}
	.card-actions-item-text_comment{
		font-size: 12px;
		color: #999;
		margin-left: 5px;
	}
</style>
